package com.yitiao.controller;

import com.yitiao.entity.PunchRecord;
import com.yitiao.service.RpcService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ImageBanner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
public class PunchRecordController {

    private final RpcService rpcService;

    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        log.info("我正在打印日志");

        PunchRecord punchRecord = PunchRecord.builder().name("111").build();
        rpcService.insert(punchRecord);

        System.out.println(ImageBanner.class.getClassLoader());
        return "Hello Nacos Discovery " + string;
    }

    @SneakyThrows
    @GetMapping(value = "/record/list")
    public String recordList() {
        log.info("获取记录列表");
        List<PunchRecord> records = rpcService.recordList();
        Thread.sleep(2000);
        return "record size:" + records.size();
    }
}
